<?php

/**
 * @author 陈韵
 * GDF会员购
 */
namespace App\Service\OrderService\OrderRouteService;
use App\Service\Code\Normal;
use App\Service\OrderService\BaseSupplierRouterService;
use App\Service\VendorClient\Shopgdf\ShopgdfApiClient;
use App\Service\TraitService\SupplierRouterOrderTrait;

class Shopgdf extends BaseSupplierRouterService
{
    use SupplierRouterOrderTrait;

    /**
     * 订单支付
     * @param array $param
     * @return mixed
     */
    public function orderPay( $param = [] )
    {
        return $this->callSdkApi(ShopgdfApiClient::class,$param['apiBody'])->createOrder($param);
    }
    
    /**
     * 订单取消
     * @param array $param
     * @return mixed
     */
    public function orderCancel( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
    
    /**
     * 订单售后
     * @param array $param
     * @return mixed
     */
    public function orderAfterSale($param = [])
    {
        return $this->callSdkApi(ShopgdfApiClient::class,$param['apiBody'])->cancelOrder($param);
    }
    
    
    /**
     * 商品列表查询接口
     * @param array $param
     */
    public function queryGoodsList( $param = [] )
    {
        $res = $this->callSdkApi(ShopgdfApiClient::class,$param['apiBody'])->{__FUNCTION__}($param['queryBody']);
        if( $res['code'] != Normal::SUC ) {
            return $res;
        }
        return Normal::returnCode(Normal::SUC,"获取成功",[
            'total' => $res['data']['count'],
            'list'  => $res['data']['list']
        ]);
    }
    
    /**
     * 获取物流信息
     * @param array $param
     */
    public function queryOrderExpress( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
    
    /**
     * 获取每个供应商接口响应报文
     * @param array $response
     */
    public function getResponseCode( $response = [],$request = [] )
    {
        $res = HttpCurl::instance()->getMicorServiceResponseInfo($response);
        if( $res['code'] == Normal::SUC ) {
            return Normal::returnCode(Normal::SUC,"操作成功",[
                'orderDeclareContents'  => $res['data']
            ]);
        }
        return Normal::returnCode(Normal::FAIL,$res['msg'],[
            'orderDeclareContents' => ''
        ]);
    }
    
    /**
     * 获取每个供应商接口响应报文
     * @param array $response
     */
    public function getResultCode( $response = [],$request = [] )
    {
        $res = HttpCurl::instance()->getMicorServiceResponseInfo($response);
        if( $res['code'] == Normal::SUC ) {
            return Normal::returnCode(Normal::SUC,"操作成功",$res['data']);
        }
        return Normal::returnCode(Normal::FAIL,$res['msg'],$res['data']);
    }
    
    /**
     * 获取响应code
     * @param array $param
     */
    public function getCreateOrderCode( $param = [] )
    {
        $res = HttpCurl::instance()->getMicorServiceResponseInfo($param);
        if( $res['code'] == Normal::SUC ) {
            return Normal::returnCode($res['code'],"OK",[
                'supplier_csn' => IdService::instance()->getOtherID()
            ]);
        }
        return $res;
    }
}